
//function PropCore.ValidAction(self, entity, cmd)
//	local ply = self.player
//	if(cmd=="spawn" or cmd=="Tdelete") then return true end
//	if(!validPhysics(entity)) then return false end
//	if(!isOwner(self, entity)) then return false end
//	if entity:IsPlayer() then return false end
//	if(!validEntity(entity)) then return false end
//	return sbox_E2_PropCore:GetInt()==2 or (sbox_E2_PropCore:GetInt()==1 and ply:IsAdmin())
//end
//if not PropCore.ValidAction(self, nil, "spawn") then return nil end

EnvExp = {}

function EnvExp.ValidAction(self, entity, cmd)
local ply = self.player
if(cmd=="isnode" or cmd=="canlink" or cmd=="resources") then return true end
if(!isOwner(self, entity)) then return false end
return ply:IsAdmin()
end

function EnvExp.AdminAction(self)
local ply = self.player
return ply:IsAdmin()
end

e2function void entity:link(entity ent2)
	if not EnvExp.ValidAction(self, this, "spawn") then return nil end
	if not EnvExp.ValidAction(self, ent2, "spawn") then return nil end
	if !validEntity(this) or !validEntity(ent2) then return void end
		if not this.IsNode and ent2.IsNode then
			if this.Link and ent2.Link then
				this:Link(ent2)
				ent2:Link(this)
			end
		end
	return void
end

e2function void entity:unlink(entity ent2)
	if not EnvExp.ValidAction(self, this, "unlink") then return nil end
	if !validEntity(this) then return void end
		if not this.IsNode and this.Link then
			this:Unlink()
		else
			if !validEntity(ent2) then
				ent:Unlink(ent2)
			end
		end
	return void
end

e2function void entity:makeresources(string name,amount)
if not EnvExp.AdminAction(self) then return nil end
	if not validEntity(this) then return 0 end
	if this.Link and not this.IsNode then 
		this:SupplyResource(name, amount)
	end
end

e2function void entity:useresources(string name,amount)
if not EnvExp.AdminAction(self) then return nil end
	if not validEntity(this) then return 0 end
	if this.Link and not this.IsNode then 
		this:ConsumeResource(name, amount)
	end
end

e2function number entity:getresources(string name)
if not validEntity(this) then return 0 end
if not this.Link then return 0 end
return this:GetResourceAmount(name)
end

e2function number entity:getnetcapacity(string name)
if not validEntity(this) then return 0 end
if not this.Link then return 0 end
return this:GetNetworkCapacity(name)
end

e2function number entity:getcapacity(string name)
if not validEntity(this) then return 0 end
if not this.Link or this.IsNode then return 0 end
return this:GetUnitCapacity(name)
end

e2function number entity:isnode()
	if not validEntity(this) then return 0 end
	if not this.IsNode then return 0 end
	return 1
end

e2function number entity:canlink()
	if not validEntity(this) then return 0 end
	if not this.Link then return 0 end
	return 1
end